package lambdasinaction.chap3.function;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class PredicateTest {

    public static void main(String ...args){
        List<String> list = Arrays.asList("asghhh", "wxrvt", "ploun", "qmozx");
        List<String> collect = list.stream()
                .filter(s -> s.length() > 5)
                .collect(Collectors.toList());
        System.out.println(collect);


        //使用Predicate过滤
        List<String> predicateFilter = filterByLength(list, s -> s.length() > 5);
        System.out.println(predicateFilter);



    }








    public static <T> List<T> filterByLength(List<T> list,Predicate<T> p){
        List<T> result = new ArrayList<>();
        for (T t : list){
            if(p.test(t)){
                result.add(t);
            }
        }
        return result;
    }







}
